/**
 * 
 */
package com.rio.dandan.dao.impl;

import java.util.List;

import com.rio.dandan.bean.PageBean;
import com.rio.dandan.dao.DaoSupport;
import com.rio.dandan.dao.UserMailDao;
import com.rio.dandan.pojo.UserMail;

/**
 * UserMailDaoImpl.java
 * 
 * @author 宋陆
 * @version 1.0 2014-7-14
 */
public class UserMailDaoImpl extends DaoSupport implements UserMailDao {

    /**
     * @see com.rio.dandan.dao.UserMailDao#getUserMail(java.lang.String)
     */
    @Override
    public UserMail getUserMail(String mailId) {
        return get(UserMail.class, mailId);
    }

    /**
     * @see com.rio.dandan.dao.UserMailDao#findUserSendMail(com.rio.dandan.bean.PageBean,
     *      java.lang.String)
     */
    @SuppressWarnings("unchecked")
    @Override
    public PageBean<UserMail> findUserSendMail(PageBean<UserMail> pageBean, String sendUid) {
        String listHql = "from UserMail as m where m.sendStatus<>-1 and m.sendUid=? order by m.createTime desc";
        String countHql = "select count(*) from UserMail as m where m.sendStatus<>-1 and m.sendUid=?";
        Object[] params = new Object[] { sendUid };
        List<UserMail> rows = super.find(listHql, params, pageBean.getStart(), pageBean.getLimit(), true);
        pageBean.setRows(rows);
        int total = super.count(countHql, params);
        pageBean.setTotal(total);
        return pageBean;
    }

    /**
     * @see com.rio.dandan.dao.UserMailDao#findUserReceiveMail(com.rio.dandan.bean.PageBean,
     *      java.lang.String)
     */
    @SuppressWarnings("unchecked")
    @Override
    public PageBean<UserMail> findUserReceiveMail(PageBean<UserMail> pageBean, String receiveUid) {
        String listHql = "from UserMail as m where m.receiveStatus<>-1 and m.receiveUid=? order by m.createTime desc";
        String countHql = "select count(*) from UserMail as m where m.receiveStatus<>-1 and m.receiveUid=?";
        Object[] params = new Object[] { receiveUid };
        List<UserMail> rows = super.find(listHql, params, pageBean.getStart(), pageBean.getLimit(), true);
        pageBean.setRows(rows);
        int total = super.count(countHql, params);
        pageBean.setTotal(total);
        return pageBean;
    }

    /**
     * @see com.rio.dandan.dao.UserMailDao#saveOrUpdateUserMail(com.rio.dandan.pojo.UserMail)
     */
    @Override
    public UserMail saveOrUpdateUserMail(UserMail userMail) {
        super.saveOrUpdate(userMail);
        return userMail;
    }

}
